<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class Product extends Model
{

    protected $fillable = ['name', 'brand_id', 'image', 'sort'];

    public function brand()
    {
        return $this->belongsTo(Brand::class);
    }

    public function getImageAttribute($image)
    {
        if(!preg_match("/^(http:\/\/|https:\/\/).*$/", $image)){
            return 'https://' . config('filesystems.disks.oss.bucket') . '.' . config('filesystems.disks.oss.endpoint') . '/' . $image;
        }

        return $image;
    }
}
